
 let form = document.querySelector('form');
 let nameInp = document.querySelector('input[name=username]');
 let pwdInp = document.querySelector('input[name=password]');
let remInp = document.querySelector('input[name=remember]')
 let btn = document.querySelectorAll('button');
//   console.log(btn);
 // 给表单提交事件
 form.addEventListener('submit',subFn);
 async function subFn(e) {
   e = e || window.event;
   e.preventDefault();
   // 获取输入的信息
   let username = nameInp.value;
   let password = pwdInp.value;
   // 判断勾选框是否选中,通过元素的checked属性值
   let rember = remInp.checked;
   
   // 不为空校验
    if(!username ) return layer.msg('用户名不能为空');
    if(!password ) return layer.msg('请输入密码');

    var agree = document.querySelector("[name='agree']");
   if (!agree.checked) {
       layer.msg('请同意协议')
       return false;
   }
  //  console.log( username,password,rember);
   let res = await pAjax( {
     url:"../server/login.php",
       method:'post',
       data:{username,password},
       dataType:"json", } )
       var { meta: { status, msg } } = res;
       var msgIndex = layer.confirm(msg);
           if(res["meta"]["status"]===0){
       // 跳转 用户名页面,并设置cookie
       // 判断是否勾选了七天免登录
       if(rember) setCookie('username',username,{expires:7*24*60*60})
       else setCookie('username',username);
       setTimeout(() => {
        location.href = '../HTML/index.html'
    }, 2000)
     }}